home *** CD-ROM | disk | FTP | other *** search
- /*
- File: CompositeDriverDescription.c
-
- Contains: Composite Class Driver Definition Header
-
- Version: xxx put version here xxx
-
- Copyright: © 1997-1998 by Apple Computer, Inc., all rights reserved.
-
- */
-
- #include <Types.h>
- #include <Devices.h>
- #include <DriverServices.h>
- #include <USB.h>
-
-
- #include "CompositeClassDriver.h"
- #include "CompositeClassVersion.h"
-
- usbCompositePBStruct newInterfacesPB;
-
-
- OSStatus CompositeDriverInitInterface(
- UInt32 interfaceNum,
- USBInterfaceDescriptor *interfaceDesc,
- USBDeviceDescriptor *deviceDesc,
- USBDeviceRef device);
-
- //------------------------------------------------------
- //
- // This is the driver description structure that the expert looks for first.
- // If it's here, the information within is used to match the driver
- // to the device whose descriptor was passed to the expert.
- // Information in this block is also used by the expert when an
- // entry is created in the Name Registry.
- //
- //------------------------------------------------------
- USBDriverDescription TheUSBDriverDescription =
- {
- // Signature info
- kTheUSBDriverDescriptionSignature,
- kInitialUSBDriverDescriptor,
-
- // Device Info
- 0, // vendor = not device specific
- 0, // product = not device specific
- 0, // version of product = not device specific
- 0, // protocol = not device specific
-
- // Interface Info (* I don't think this would always be required...*)
- 0, // Configuration Value
- 0, // Interface Number
- 0, // Interface Class
- 0, // Interface SubClass
- 0, // Interface Protocol
-
-
- // Driver Info
- "\pUSBCompositeDevice", // Driver name for Name Registry
- kUSBCompositeClass, // Device Class (from USBDeviceDefines.h)
- kUSBCompositeSubClass, // Device Subclass
- kCMPHexMajorVers,
- kCMPHexMinorVers,
- kCMPCurrentRelease,
- kCMPReleaseStage, // version of driver
-
- // Driver Loading Info
- kUSBDoNotMatchInterface // Please don't load us as an interface driver.
- };
-
- USBClassDriverPluginDispatchTable TheClassDriverPluginDispatchTable =
- {
- kClassDriverPluginVersion, // Version of this structure
- CompositeDriverValidateHW, // Hardware Validation Procedure
- CompositeDriverInitialize, // Initialization Procedure
- CompositeDriverInitInterface, // Interface Initialization Procedure
- CompositeDriverFinalize, // Finalization Procedure
- CompositeDriverNotifyProc // Driver Notification Procedure
- };
-
- // hubDriverInitInterface function
- // Called to initialize driver for an individual interface - either by expert or
- // internally by driver
- OSStatus CompositeDriverInitInterface(
- UInt32 interfaceNum,
- USBInterfaceDescriptor *interfaceDesc,
- USBDeviceDescriptor *deviceDesc,
- USBDeviceRef device)
- {
- #pragma unused (interfaceNum)
- #pragma unused (interfaceDesc)
- #pragma unused (deviceDesc)
- #pragma unused (device)
-
- return (OSStatus)kUSBNoErr;
- }
-
- OSStatus CompositeDriverNotifyProc(UInt32 notification, void *pointer)
- {
- #pragma unused (pointer)
- #pragma unused (notification)
- return(kUSBNoErr);
- }
-
- // Hardware Validation
- // Called upon load by Expert
- OSStatus CompositeDriverValidateHW(USBDeviceRef device, USBDeviceDescriptor *desc)
- {
- #pragma unused (device)
- #pragma unused (desc)
-
- return (OSStatus)kUSBNoErr;
- }
-
- // Initialization function
- // Called upon load by Expert
- OSStatus CompositeDriverInitialize (USBDeviceRef device, USBDeviceDescriptorPtr pDesc, UInt32 busPowerAvailable)
- {
- #pragma unused (busPowerAvailable)
-
- // until we get going, it's okay to accept a call to finalize
- newInterfacesPB.okayToFinalizeFlag = true;
- DeviceInitialize(device, pDesc, busPowerAvailable);
- return (OSStatus)kUSBNoErr;
- }
-
- // Termination function
- // Called by Expert when driver is being shut down
- OSStatus CompositeDriverFinalize(USBDeviceRef theDeviceRef, USBDeviceDescriptorPtr pDesc)
- {
- #pragma unused (pDesc)
- UInt32 i;
- OSStatus myErr;
-
- // If all the interfaces have been examined and had their interface
- // drivers loaded, then go ahead and removed them all
- // otherwise just return with a device busy error code.
- USBExpertStatus(newInterfacesPB.pb.usbReference, "\pComposite Driver: Finalize", newInterfacesPB.pb.usbStatus);
- if (theDeviceRef == newInterfacesPB.deviceRef)
- {
- if (newInterfacesPB.okayToFinalizeFlag)
- {
- USBExpertStatus(newInterfacesPB.pb.usbReference, "\pComposite Driver: Removing Interface drivers & InterfaceRefs", newInterfacesPB.pb.usbStatus);
- for (i=0; i < newInterfacesPB.interfaceCount; i++)
- {
- USBExpertRemoveInterfaceDriver(newInterfacesPB.interfaceRefArray[i]);
- InitParamBlock(newInterfacesPB.deviceRef, &newInterfacesPB.pb);
- newInterfacesPB.pb.usbRefcon = 0;
- newInterfacesPB.pb.usbWIndex = i;
- newInterfacesPB.pb.usbCompletion = (USBCompletion)-1;
- myErr = USBDisposeInterfaceRef(&newInterfacesPB.pb);
- }
-
- InitParamBlock(newInterfacesPB.deviceRef, &newInterfacesPB.pb);
- newInterfacesPB.pb.usbRefcon = 0;
- newInterfacesPB.pb.usbBuffer = newInterfacesPB.pFullConfigDescriptor;
- newInterfacesPB.pb.usbCompletion = (USBCompletion)-1;
- myErr = USBDeallocMem(&newInterfacesPB.pb);
- return (OSStatus)kUSBNoErr;
- }
- else
- {
- return (OSStatus)kUSBDeviceBusy;
- }
- }
- else
- {
- USBExpertFatalError(newInterfacesPB.pb.usbReference, kUSBInternalErr, "\pComposite Driver - Finalize received unknown deviceRef", newInterfacesPB.pb.usbRefcon);
- return (OSStatus)kUSBUnknownDeviceErr;
- }
- }
-
- void DeviceInitialize(USBDeviceRef device, USBDeviceDescriptorPtr pDeviceDescriptor, UInt32 busPowerAvailable)
- {
- static Boolean beenThereDoneThat = false;
-
- if(beenThereDoneThat)
- {
- USBExpertFatalError(device, kUSBInternalErr, "\pComposite driver is not reentrant!", 0);
- return;
- }
- beenThereDoneThat = true;
- newInterfacesPB.okayToFinalizeFlag = false;
-
- newInterfacesPB.deviceRef = device;
- newInterfacesPB.deviceDescriptor = *pDeviceDescriptor;
-
- newInterfacesPB.busPowerAvailable = busPowerAvailable;
- newInterfacesPB.delayLevel = 0;
- newInterfacesPB.transDepth = 0;
- newInterfacesPB.retryCount = kCompositeRetryCount;
- newInterfacesPB.pFullConfigDescriptor = nil;
-
- InitParamBlock(device, &newInterfacesPB.pb);
- newInterfacesPB.pb.usbRefcon = kGetFullConfiguration0; /* Start out at first state */
-
- // DebugStr("\pIn Composite Driver");
- CompositeDeviceInitiateTransaction(&newInterfacesPB.pb);
- }
-
-
-